<?php
class LoadsController extends AppController{
	var $uses=null;	
	function load($detailid, $filename, $date, $hospitalname){		
		$targetfile=FILES.DS.$date.DS.$hospitalname.DS.$filename;				
		if(file_exists($targetfile)){
			App::import('Vendor','excel');
			$data = new Spreadsheet_Excel_Reader($targetfile);
			
			$rowcount=$data->rowcount();
			$colcount=$data->colcount();
			$header=$data->val(1,1);
						
			if($header=='patients'){								
				for($r=3; $r<=$rowcount; $r++){
					for($c=1; $c<=$colcount; $c++){
						$info[]=$data->val($r,$c);					
					}
					$this->ames($info);
					$info=null;					
				}					
			}			
			else if($header=='drugs'){
				for($r=3; $r<=$rowcount; $r++){
					for($c=1; $c<=$colcount; $c++){
						$info[]=$data->val($r,$c);					
					}					
					$this->drugs($info);
					$info=null;					
				}
			}
			else if($header=='others'){
				for($r=3; $r<=$rowcount; $r++){
					for($c=1; $c<=$colcount; $c++){
						$info[]=$data->val($r,$c);					
					}					
					//var_dump($info); echo '<br><br>';
					$this->others($info);
					$info=null;										
				}
			}
			else if($header=='visitors'){
				for($r=3; $r<=$rowcount; $r++){
					for($c=1; $c<=$colcount; $c++){
						$info[]=$data->val($r,$c);
					}
					$this->physicians($info);
					$info=null;
					//$this->visitors($info);
					//$info=null;
				}
			}
			else if($header=='surgeons'){
				for($r=3; $r<=$rowcount; $r++){
					for($c=1; $c<=$colcount; $c++){
						$info[]=$data->val($r,$c);
					}
					$this->surgeons($info);
					$info=null;
				}
			}
			else if($header=='anesthesiologists'){
				for($r=3; $r<=$rowcount; $r++){
					for($c=1; $c<=$colcount; $c++){
						$info[]=$data->val($r,$c);
					}
					$this->anestheologists($info);
					$info=null;
				}
			}			
			else if($header=='physicians'){
				for($r=3; $r<=$rowcount; $r++){
					for($c=1; $c<=$colcount; $c++){
						$info[]=$data->val($r,$c);
					}
					$this->physicians($info);
					$info=null;
				}
			}
			$this->requestAction('/details/setStatus', array('pass'=>array($detailid, 1)));
		}	
		else{$this->redirect('/loads/filenotfound');}	
	}
	function anestheologists($data){
		$this->requestAction('/anesthesiologists/insert/', array('pass' => array($data)));
		$this->requestAction('/evaluatedanesthesiologists/insert/', array('pass' => array($data)));
	}
	function surgeons($data){
		$this->requestAction('/surgeons/insert/', array('pass' => array($data)));
		$this->requestAction('/evaluatedsurgeons/insert/', array('pass' => array($data)));
	}
	function filenotfound() {
	}	
	function ames($data){		
		$this->requestAction('/patients/insert/', array('pass' => array($data)));
	}
	function drugs($data){
		$this->requestAction('/drugs/insert/', array('pass' => array($data)));
		$this->requestAction('/evaluateddrugs/insert/', array('pass' => array($data)));
	}
	function others($data){
		$this->requestAction('/others/insert/', array('pass' =>array($data)));
		$this->requestAction('/evaluatedothers/insert/', array('pass' =>array($data)));
	}
	function physicians($data){
		$this->requestAction('/physicians/insert/', array('pass' =>array($data)));
		$this->requestAction('/evaluatedphysicians/insert/', array('pass' =>array($data)));
	}
}
?>